package cn.mrlong.segmentcontrol;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    String[] titles = new String[]{"本地数据","服务器数据"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        SegmentControl sc = findViewById(R.id.sc);
        sc.setTitles(titles);
        sc.setTextColor(getResources().getColor(R.color.black));
        sc.setSelectedTextColor(getResources().getColor(R.color.white));
        //sc.setTextSize(10);
        sc.setOnSegmentListener(new SegmentControl.OnSegmentListener() {
            @Override
            public void setOnSegment(View v, int position) {
                Toast.makeText(MainActivity.this,titles[position],Toast.LENGTH_SHORT).show();
            }
        });
    }
}
